package com.xiaoluo.web;

import com.xiaoluo.cd.entity.base.Jobs;
import com.xiaoluo.cd.entity.base.SysUser;
import com.xiaoluo.common.utils.AesUtils;
import com.xiaoluo.service.UserService;
import com.xiaoluo.web.form.ProjectForm;
import com.xiaoluo.web.form.SysUserForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Project : XL-CD
 * Package : com.xiaoluo.web
 * Created by Willian.
 * Date  : 2016/1/15 14:29.
 */
@Controller
@RequestMapping("/user")
public class UserController extends BaseController{

    private final static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    /**
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/list")
    public  String list(ModelMap model,HttpServletRequest request){

        List<SysUser> list = userService.list();
        model.addAttribute("users",list);

        return "users/list";
    }
    @RequestMapping(value = "/edit",method = RequestMethod.GET)
    public  String edit(ModelMap model,Long id){
        logger.info("User:{},edit User:{}",getCurrentUser().getUserName(),id);

        if(id != null){
            SysUser user = userService.get(id);
            model.addAttribute("user",user);
        }
        return "users/edit";
    }
    @RequestMapping(value = "/save")
    public  String save(ModelMap model,SysUserForm user){
        logger.info("save User:{}",getCurrentUser().getUserName());

        userService.save(user);
        return "forward:list";
    }
}
